home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performUngroup.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.6 KB  |  389 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  7 July 1997
  22. //
  23. //  Description:
  24. //
  25. //        Ungroup the selected objects.
  26. //
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. proc setOptionVars(int $forceFactorySettings)
  42. {
  43.     //    World flag
  44.     //
  45.     if ($forceFactorySettings || !`optionVar -exists ungroupWorld`) {
  46.         optionVar -intValue ungroupWorld false;
  47.     }
  48.  
  49.     //    Absolute flag
  50.     //
  51.     if ($forceFactorySettings || !`optionVar -exists ungroupPreserve`) {
  52.         optionVar -intValue ungroupPreserve true;
  53.     }
  54. }
  55.  
  56. //
  57. //  Procedure Name:
  58. //      performUngroupSetup
  59. //
  60. //  Description:
  61. //        Update the state of the option box UI to reflect the option values.
  62. //
  63. //  Input Arguments:
  64. //      parent               - Top level parent layout of the option box UI.
  65. //                             Required so that UI object names can be 
  66. //                             successfully resolved.
  67. //
  68. //    forceFactorySettings - Whether the option values should be set to
  69. //                             default values.
  70. //
  71. //  Return Value:
  72. //      None.
  73. //
  74. global proc performUngroupSetup(string $parent, int $forceFactorySettings)
  75. {
  76.     int $boolToOption[] = { 1, 2 };
  77.  
  78.     // Retrieve the option settings
  79.     //
  80.     setOptionVars ($forceFactorySettings);
  81.     setParent $parent;
  82.  
  83.     //    World flag
  84.     //
  85.     int $world = `optionVar -q ungroupWorld`;
  86.     radioButtonGrp -e -select $boolToOption[$world] ungroupUnder;
  87.  
  88.     //    Absolute flag
  89.     //
  90.     int $preserve = `optionVar -q ungroupPreserve`;
  91.     checkBoxGrp -e -v1 $preserve ungroupCheck;
  92. }
  93.  
  94. //
  95. //  Procedure Name:
  96. //      performUngroupCallback
  97. //
  98. //  Description:
  99. //        Update the option values with the current state of the option box UI.
  100. //
  101. //  Input Arguments:
  102. //      parent - Top level parent layout of the option box UI.  Required so
  103. //               that UI object names can be successfully resolved.
  104. //
  105. //    doIt   - Whether the command should execute.
  106. //
  107. //  Return Value:
  108. //      None.
  109. //
  110. global proc performUngroupCallback(string $parent, int $doIt)
  111. {
  112.     setParent $parent;
  113.  
  114.     int $optionToBool[] = { 0, false, true };
  115.     setParent $parent;
  116.  
  117.     // Set the optionVar's from the control values, and then perform command
  118.     //
  119.  
  120.     //    World flag
  121.     //
  122.     int $i = `radioButtonGrp -q -select ungroupUnder`;
  123.     optionVar -intValue ungroupWorld $optionToBool[$i];
  124.  
  125.     //    Preserve flag
  126.     //
  127.     optionVar -intValue ungroupPreserve `checkBoxGrp -q -v1 ungroupCheck`;
  128.  
  129.     if ($doIt) {
  130.         performUngroup 0; 
  131.         addToRecentCommandQueue "performUngroup 0" "Ungroup";
  132.     }
  133. }
  134.  
  135. //
  136. //  Procedure Name:
  137. //      performUngroupOptions
  138. //
  139. //  Description:
  140. //        Construct the option box UI.  Involves accessing the standard option
  141. //        box and customizing the UI accordingly.
  142. //
  143. //  Input Arguments:
  144. //      None.
  145. //
  146. //  Return Value:
  147. //      None.
  148. //
  149. proc performUngroupOptions()
  150. {
  151.     //    Name of the command for this option box.
  152.     //
  153.     string $commandName = "performUngroup";
  154.  
  155.     //    Build the option box actions.
  156.     //
  157.     string $callback = ($commandName + "Callback");
  158.     string $setup = ($commandName + "Setup");
  159.  
  160.     //    STEP 1:  Get the option box.
  161.     //    ============================
  162.     //
  163.     //    The value returned is the name of the layout to be used as
  164.     //    the parent for the option box UI.
  165.     //
  166.     string $layout = getOptionBox();
  167.     setParent $layout;
  168.     
  169.     //    STEP 2:  Pass the command name to the option box - see STEP 8.
  170.     //    ==============================================================
  171.     
  172.     //    STEP 3:  Activate the default UI template.
  173.     //    ==========================================
  174.     //
  175.     //    Activate the default UI template so that the layout of this 
  176.     //    option box is consistent with the layout of the rest of the 
  177.     //    application.
  178.     //
  179.     setUITemplate -pushTemplate DefaultTemplate;
  180.  
  181.     //    STEP 4: Create option box contents.
  182.     //    ===================================
  183.     //    
  184.     //    This, of course, will vary from option box to option box.    
  185.     
  186.     //    Turn on the wait cursor.
  187.     //
  188.     waitCursor -state 1;
  189.  
  190.     //    RECOMMENDATION:  Place the UI in a 'scrollable' layout.  A 
  191.     //    scrollable layout ensures that if the option box window is ever
  192.     //    resized such that it's entire contents is not visible then the 
  193.     //    scroll bars provided by the scrollable layout will allow the user
  194.     //    to access the hidden UI.  Two layouts currently supporting 
  195.     //    scrollable behaviour are the 'scrollLayout' and the 'tabLayout'.
  196.     //
  197. //    scrollLayout;
  198.     //
  199.     //    or...
  200.     //
  201.     tabLayout -tabsVisible 0 -scrollable 1;
  202.     
  203.     string $parent = `columnLayout -adjustableColumn 1`;
  204.     
  205.     //    RECOMMENDATION:  Use the 'Grp' commands where possible because
  206.     //    they obey the formatting specified in the default template.
  207.     //    This will result in a more consistent look throughout the
  208.     //    application.
  209.     //    
  210.  
  211.     radioButtonGrp -numberOfRadioButtons 2
  212.         -label "Ungroup Under"
  213.         -label1 "Parent"
  214.         -label2 "World"
  215.         ungroupUnder;
  216.  
  217.     checkBoxGrp -numberOfCheckBoxes 1
  218.         -label1 "Preserve Position"
  219.         ungroupCheck;
  220.  
  221.     //    Turn off the wait cursor.
  222.     //
  223.     waitCursor -state 0;
  224.     
  225.     //    Step 5: Deactivate the default UI template.
  226.     //    ===========================================
  227.     //
  228.     setUITemplate -popTemplate;
  229.  
  230.     //    Step 6: Customize the buttons.  
  231.     //    ==============================
  232.     //
  233.     //    Provide more descriptive labels for the buttons.  This is not 
  234.     //    necessary, but in some cases, for example, a button labelled 
  235.     //    'Create' may be more meaningful to the user than one labelled
  236.     //    'Apply'.
  237.     //
  238.     //    Disable those buttons that are not applicable to the option box.
  239.     //
  240.     //    Attach actions to those buttons that are applicable to the option
  241.     //    box.  Note that the 'Close' button has a default action attached 
  242.     //    to it that will hide the window.  If a a custom action is
  243.     //    attached to the 'Close' button then be sure to call the 'hide the
  244.     //    option box' procedure within the custom action so that the option
  245.     //    box is hidden properly.
  246.  
  247.     //    'Apply' button.
  248.     //
  249.     string $applyBtn = getOptionBoxApplyBtn();
  250.     button -edit
  251.         -label "Ungroup"
  252.         -command ($callback + " " + $parent + " " + 1)
  253.         $applyBtn;
  254.  
  255.     //    'Save' button.
  256.     //
  257.     string $saveBtn = getOptionBoxSaveBtn();
  258.     button -edit 
  259.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  260.         $saveBtn;
  261.  
  262.     //    'Reset' button.
  263.     //
  264.     string $resetBtn = getOptionBoxResetBtn();
  265.     button -edit 
  266.         -command ($setup + " " + $parent + " " + 1)
  267.         $resetBtn;
  268.  
  269.     //    Step 7: Set the option box title.
  270.     //    =================================
  271.     //
  272.     setOptionBoxTitle("Ungroup Options");
  273.  
  274.     //    Step 8: Customize the 'Help' menu item text.
  275.     //    ============================================
  276.     //
  277.     setOptionBoxHelpTag( "Ungroup" );
  278.  
  279.     //    Step 9: Set the current values of the option box.
  280.     //    =================================================
  281.     //
  282.     eval (($setup + " " + $parent + " " + 0));    
  283.     
  284.     //    Step 10: Show the option box.
  285.     //    =============================
  286.     //
  287.     showOptionBox();
  288. }
  289.  
  290. //
  291. //  Procedure Name:
  292. //      performUngroupHelp
  293. //
  294. //  Description:
  295. //        Return a short description about this command.
  296. //
  297. //  Input Arguments:
  298. //      None.
  299. //
  300. //  Return Value:
  301. //      string.
  302. //
  303. proc string performUngroupHelp()
  304. {
  305.  
  306.     return 
  307.     "  Command: Ungroup - Ungroups the selected object(s).\n" +
  308.     "Selection: Any objects.";
  309. }
  310.  
  311. //
  312. //  Procedure Name:
  313. //      assembleCmd
  314. //
  315. //  Description:
  316. //        Construct the command that will apply the option box values.
  317. //
  318. //  Input Arguments:
  319. //      None.
  320. //
  321. proc string assembleCmd()
  322. {
  323.     string $cmd = "performUngroup";
  324.  
  325.     setOptionVars(false);
  326.  
  327.     string  $cmd      = "ungroup";
  328.     int        $world    = `optionVar -q ungroupWorld`;
  329.     int        $preserve = `optionVar -q ungroupPreserve`;
  330.  
  331.     if ($world) $cmd += " -w";
  332.     if (!$preserve) $cmd += " -r";
  333.  
  334.     return $cmd;
  335. }
  336.  
  337. //
  338. //  Procedure Name:
  339. //      performUngroup
  340. //
  341. //  Description:
  342. //        Perform the ungroup command using the corresponding 
  343. //        option values.  This procedure will also show the option box
  344. //        window if necessary as well as construct the command string
  345. //        that will invoke the ungroup command with the current
  346. //        option box values.
  347. //
  348. //  Input Arguments:
  349. //      0 - Execute the command.
  350. //      1 - Show the option box dialog.
  351. //      2 - Return the command.
  352. //
  353. global proc string performUngroup(int $action)
  354. {
  355.     string $cmd = "";
  356.  
  357.     switch ($action) {
  358.  
  359.         //    Execute the command.
  360.         //
  361.         case 0:
  362.             //    Get the command.
  363.             //
  364.             $cmd = `assembleCmd`;
  365.  
  366.             //    Execute the command with the option settings.
  367.             //
  368.             evalEcho($cmd);
  369.  
  370.             break;
  371.  
  372.         //    Show the option box.
  373.         //
  374.         case 1:
  375.             performUngroupOptions;
  376.             break;
  377.  
  378.         //    Return the command string.
  379.         //
  380.         case 2:
  381.             //    Get the command.
  382.             //
  383.             $cmd = `assembleCmd`;
  384.             break;
  385.     }
  386.     return $cmd;
  387. }
  388.  
  389.